﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace SurveyTrackerV2.Admin
{
    public partial class EditEmail : System.Web.UI.Page
    {
        public int EmailID
        {

            get
            {
                try
                {
                    return int.Parse(Request.QueryString["id"].ToString());
                }
                catch (Exception)
                {
                    return 0;
                }

            }
        }

        public string EmailAddress { get; set; }




        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                List<int> userEmailList = GetUserEmailLists(this.EmailID);
            
                SurveyTrackerV2DB db = new SurveyTrackerV2DB();
             
                var emailLists = from el in db.Lists
                                 where el.ListStatus == 1
                                 select el;                               

                                 
                cblEmailLists.DataSource = emailLists.ToList<List>();
                cblEmailLists.DataValueField = "ListId";
                cblEmailLists.DataTextField = "ListName";

                cblEmailLists.DataBind();
            }

            

        }

        /// <summary>
        /// Gets the user email lists.
        /// </summary>
        /// <param name="p">The p.</param>
        /// <returns></returns>
        private List<int> GetUserEmailLists(int p)
        {
            List<int> emailListIds = new List<int>();
        
            SurveyTrackerV2DB db = new SurveyTrackerV2DB();
            var emailLists = from el in db.EmailLists
                             where el.EmailId == p && el.EmailListStatus == 1
                             select new
                             {
                                 EmailListID = el.EmailListId
                             };
            foreach (var item in emailLists)
            {
                emailListIds.Add(int.Parse(item.ToString()));   
            }
            return emailListIds;
        }
    }
}
